import java.util.*;

public class Test14 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int n = in.nextInt();
            int[] arr = new int[n];
            int[] brr = new int[n];
            int k = 0;
            // 统计出现的各个数字的次数
            Map<Integer, Integer> hash = new HashMap<>();
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
                hash.put(arr[i], hash.getOrDefault(arr[i], 0) + 1);
            }
            Arrays.sort(arr);
            for (int i = 0; i < n; i++) {
                if(k!=0) {
                    // 记录出现的各种数字
                    if (brr[k - 1] != arr[i]) {
                        brr[k++] = arr[i];
                    }
                }else{
                    brr[k++]=arr[i];
                }
            }
            int sum=0;
            for(int i=0;i<k;i++){
                int ret=0;
                ret+=sumSelect(brr,hash,i,k);
                sum=Math.max(sum,ret);
            }
            System.out.println(sum);
        }
    }

    public static int sumSelect(int[] brr, Map<Integer, Integer> hash, int a,int k) {
        int ret = 0;

        for (int i = 0; i < k; i++) {

            if (brr[i] != brr[a] + 1 && brr[i] != brr[a] - 1 ) {
                ret += hash.get(brr[i])*brr[i];
            }
        }
        return ret;
    }











    public static void main02(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int n = in.nextInt();
            int[] arr=new int[n*3];
            for(int i=0;i<n*3;i++){
                arr[i]=in.nextInt();
            }

            Arrays.sort(arr);
            int sum=0;
            int i = n * 3 - 2;
            while(n-- !=0){
                sum+=arr[i];
                i-=2;
            }
            System.out.println(sum);
        }
    }






    public static void main01(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            char[] a= in.nextLine().toCharArray();
            char[] b= in.nextLine().toCharArray();

            int m=a.length,n=b.length;
            Map<Character,Integer> hash=new HashMap<>();
            // 用来统计 a 中所有字符
            for(int i=0;i<m;i++){
                hash.put(a[i],hash.getOrDefault(a[i],0)+1);
            }
            for(int i=0;i<n;i++){
                hash.put(b[i],hash.getOrDefault(b[i],0)-1);
            }
            boolean bool=false;
            for(int i=0;i<n;i++){
                if(hash.get(b[i]) < 0){
                    bool=true;
                    break;
                }
            }
            if(bool){
                System.out.println("No");
            }else{
                System.out.println("Yes");
            }


        }
    }
}
